package com.tomcov.client.view;

import com.extjs.gxt.ui.client.widget.form.AdapterField;
import com.extjs.gxt.ui.client.widget.form.DateField;
import com.extjs.gxt.ui.client.widget.form.TextField;
import com.google.gwt.core.client.GWT;
import com.google.gwt.maps.client.MapOptions;
import com.google.gwt.maps.client.MapTypeId;
import com.google.gwt.maps.client.MapWidget;
import com.google.gwt.maps.client.base.LatLng;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RadioButton;
import com.google.gwt.user.client.ui.SuggestBox;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.tomcov.client.i18n.MapViewConstants;

public class MapViewImpl extends Composite implements MapView  {

	@SuppressWarnings("unused")
	private Presenter presenter;
	private static final MyUiBinder binder = GWT.create(MyUiBinder.class);
	interface MyUiBinder extends UiBinder<FlowPanel, MapViewImpl> {
	}

	@UiField(provided = true)
	MapWidget mapWidget;

	@UiField SuggestBox FromAdress,ToAdress;
	@UiField VerticalPanel directionPanel;
	@UiField Button RoadButton,AddJourneyButton;
	@UiField VerticalPanel possibleUser;
	@UiField Label Duration,Distance;
	@UiField RadioButton DriverButton,PassengerButton;
	@UiField AdapterField originField, destinationField;
	@UiField DateField dateOfJourney;
	@UiField TextField<String> departureStartTimeItem,departureEndTimeItem,arrivalTimeItem;
	@UiField TextField<String> DetourBox;

	MapViewConstants myConstants = GWT.create(MapViewConstants.class);

	public MapViewImpl(){
		MapOptions options = new MapOptions();
		options.setCenter(new LatLng(50.6687, 4.57967));
		options.setZoom(12);
		options.setMapTypeId(new MapTypeId().getRoadmap());
		options.setNavigationControl(true);
		options.setDraggable(true);
		options.setMapTypeControl(true);
		options.setScrollwheel(true);
		mapWidget = new MapWidget(options);
		mapWidget.setPixelSize(450,450);

		initWidget(binder.createAndBindUi(this));
		
	}
	

	@Override
	public void setPresenter(Presenter presenter) {
		this.presenter=presenter;

	}

	public VerticalPanel getPossibleUserPanel(){
		return possibleUser;
	}

	@Override
	public RadioButton getDriverRadioButton() {
		return DriverButton;
	}
	public RadioButton getPassengerRadioButton() {
		return PassengerButton;
	}

	@Override
	public SuggestBox getFromAddress() {
		return FromAdress;
	}

	@Override
	public SuggestBox getToAddress() {
		return ToAdress;
	}

	@Override
	public int getDetour() {
		if (DetourBox.getValue()==null){return 0;}
		return Integer.parseInt(DetourBox.getValue());
	}

	@Override
	public Button getAddJourneyButton() {
		return AddJourneyButton;
	}

	@Override
	public Button getRoadButton() {
		return RoadButton;
	}

	@Override
	public MapWidget getMap() {
		return mapWidget;
	}

	@Override
	public VerticalPanel getDirectionsPanel() {
		return directionPanel;
	}

	

	public Label getDistance(){
		return Distance;
	}

	public Label getDuration(){
		return Duration;
	}

	public DateField getDate() {
		return dateOfJourney;
	}
	public TextField<String> getArrivalTime() {
		return arrivalTimeItem;
	}

	public TextField<String> getDeptime2() {
		return departureEndTimeItem;
	}
	
	
	public TextField<String> getDeptime1() {
		return departureStartTimeItem;
	}
	
	public AdapterField getOriginField() {
		return originField;
	}

	@Override
	public AdapterField getDestinationField() {
		return destinationField;
	}


	@Override
	public void setToAddress(String text) {
		ToAdress.setText(text);
	}


	@Override
	public void setFromAddress(String text) {
		FromAdress.setText(text);
	}


}
